<?php
/** .-------------------------------------------------------------------
* |  Software: [HDCMS framework]
* |      Site: www.hdcms.com
* |-------------------------------------------------------------------
* |    Author: 向军 <2300071698@qq.com>
* |    WeChat: aihoudun
* | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
* '-------------------------------------------------------------------*/

namespace app\admin\controller;

class Brand extends Common {
    private  $db;
    public function __construct()
    {
        parent::__construct();
        $this->db=new \system\model\Brand();
    }

    //动作
    public function index(){
    //此处书写代码...
        $brandData=Db::table("brand")->paginate(5);
        $page=$brandData->links();
        View::with("brandData",$brandData)->with('page',$page);
        return view();
    }
    public function add(){
        if(IS_POST){
            if($this->db->store()){
             message("添加成功",u("index"),"success");
            }
            message($this->db->getError(),"","error");
        }
        return view();
    }
    public function edit(){
        if(IS_POST){
            if($this->db->edit()){
                message("添加成功",u("index"),"success");
            }
            message($this->db->getError(),"","error");
        }
        $bid=Q("get.bid");
        $oldBrand=Db::table("brand")->where('bid',$bid)->first();
        View::with("oldBrand",$oldBrand);
        return view();
    }

    public function del(){
        $bid=Q("b");
        $this->db->where('bid',$bid)->delete();
        //提示跳转
        message('删除成功','','success');
    }

}
